<?php
/**
 * 匠言知识付费
 * Author: 山西匠言网络科技有限公司
 * This is not a free software, it under the license terms, you can visit https://www.zsffzxkc.cn/ get more details.
 */
namespace app\admin\controller;
use org\AliSts;
use think\Db;
use org\Qiniu;

/**
 * Class 系统设置类
 * @package app\admin\controller
 */
class Set extends Base
{
    //自定义导航图标组1
    public function diypage_icons1(){
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $item=Db::name('set_diypage')
                    ->where('acid',1)
                    ->find();
                $data = input('post.');
//                var_dump($data);die;
                $data = json_encode($data);
                if (!empty($item)) {
                    $res = Db::name('set_diypage')->where('acid', 1)->setField('icons1',$data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result(0, '无更新');
                        }else{
                            $this->result(0, '修改成功');
                        }
                    } else {
                        $this->result(1, '修改失败');
                    }
                } else {
                    $data1['acid'] = 1;
                    $data1['icons1'] = $data;
                    $res = Db::name('set_diypage')->insert($data1);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
    }
    //自定义装修
    public function diypage(){
        $item=Db::name('set_diypage')
            ->where('acid',1)
            ->find();
        if(!empty($item)){
            $item1=json_decode($item['data'],true);
            $this->assign('item',$item1);
        }else{
            $this->assign('item',array(
                'is_seckill'=>'',
                'is_pintuan'=>'',
                'is_jigoushow'=>'',
                'is_zcshow'=>'',
                'is_dhlshow'=>''
            ));
        }
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                $data = json_encode($data);
                if (!empty($item)) {
                    $res = Db::name('set_diypage')->where('acid', 1)->setField('data',$data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result(0, '无更新');
                        }
                        $this->result(0, '修改成功');
                    } else {
                        $this->result(1, '修改失败');
                    }
                } else {
                    $data1['acid'] = 1;
                    $data1['data'] = $data;
                    $res = Db::name('set_diypage')->insert($data1);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    //付费问答
    public function wenda(){
        $item=Db::name('set_wenda')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                $data['yj'] = $data['yj'] / 100;
                if(isset($data['file'])){
                    unset($data['file']);
                }
                if (!empty($item)) {
                    $res = Db::name('set_wenda')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_wenda')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    //付费资源下载
    public function filesdownload(){
        $item=Db::name('set_filesdownload')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                $data['yj'] = $data['yj'] / 100;
                if(isset($data['file'])){
                    unset($data['file']);
                }
                if (!empty($item)) {
                    $res = Db::name('set_filesdownload')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_filesdownload')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    //合成证书设置
    public function cert(){
        $item=Db::name('set_cert')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if(isset($data['file'])){
                    unset($data['file']);
                }
                if (!empty($item)) {
                    $res = Db::name('set_cert')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_cert')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    /*
     * 用户注册协议
     * */
    public function xieyi(){
        if(request()->isAjax()) {
            $data = input('post.');
            if($data['id'] !== ""){
                $data1=array(
                    'about'=>$data['about'],
                    'yinsi'=>$data['yinsi'],
                    'fuwu'=>$data['fuwu'],
                );
                $res=Db::name('vipxieyi')->where('acid',1)->where('id',$data['id'])->update($data1);
                if($res){
                    if($res==0){
                        $this->result('0','无更新');
                    }else{
                        $this->result('0','修改成功');
                    }
                }else{
                    $this->result('1','修改失败');
                }
            }else{
                $data1=array(
                    'about'=>$data['about'],
                    'yinsi'=>$data['yinsi'],
                    'fuwu'=>$data['fuwu'],
                    'addtime'=>time(),
                    'acid'=>1
                );
                $res=Db::name('vipxieyi')->where('acid',1)->insert($data1);
                if($res){
                    $this->result('0','添加成功');
                }else{
                    $this->result('1','添加失败');
                }
            }
        }
        $data = Db::name('vipxieyi')->find();
        if($data){
            $this->assign('item',$data);
        }else{
            $this->assign('item',array());
        }
        return $this->fetch();
    }

    public function storage(){
        $item=Db::name('storage')
            ->where('acid',1)
            ->find();
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                unset($data['file']);
                if (!empty($item)) {
                    $res = Db::name('storage')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('storage')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        if($item['upload_area'] == 1) {
            $qiniu =json_decode($item['qiniu'], true);
            $item['domain'] = $qiniu['domain'];
        } elseif($item['upload_area'] == 2) {
            $ali =json_decode($item['ali'], true);
            $item['domain'] = $ali['oss']['accessUrl'];
        } elseif($item['upload_area'] == 3) {
            //腾讯云
            $tencent =json_decode($item['tencent'], true);
            $item['domain'] = $tencent['domain'];
        } else {
            //本地图片兼容 前台拼接域名
            $item['domain'] = request()->domain();
        }
        $this->assign('item',$item);
        return $this->fetch();
    }
    public function storageQiniu(){
        $item=Db::name('storage')
            ->where('acid',1)
            ->find();
        $this->assign('item', json_decode($item['qiniu'], true));
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                unset($data['file']);
                if (!empty($item)) {
                    $res = Db::name('storage')->where('acid', 1)->update(['qiniu' => json_encode($data)]);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('storage')->insert(['qiniu' => json_encode($data)]);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function storageAli(){
        $item=Db::name('storage')
            ->where('acid',1)
            ->field('ali')
            ->find();
        $this->assign('item', json_decode($item['ali'], true));
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('storage')->where('acid', 1)->update(['ali' => json_encode($data)]);

                    //修改水印模板
                    /*$old = json_decode($item['ali']);
                    $WaterMarkTemplateId = $old[''];
                    $name = 'ceshi';
                    $templateconfig = array(
                        'Dx'=>'10',
                        'Dy'=>'5',
                        'ReferPos'=>$data['watermark_location'],
                        'Type'=>'Image',
                        'Timeline'=>array(
                            'Start'=>'0',
                            'Duration'=>'10'
                        )
                    );
                    $alists = new AliSts();
                    $result = $alists->updateWaterMarkTemplate($WaterMarkTemplateId,$name,$templateconfig);*/

                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('storage')->insert(['ali' => json_encode($data)]);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function storageTenent(){
        $item=Db::name('storage')
            ->where('acid',1)
            ->find();
        $this->assign('item', json_decode($item['tencent'], true));
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('storage')->where('acid', 1)->update(['tencent' => json_encode($data)]);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('storage')->insert(['tencent' => json_encode($data)]);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function pintuan(){
        $item=Db::name('set_pintuan')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_pintuan')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_pintuan')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function seckill(){
        $item=Db::name('set_seckill')
            ->where('acid',1)
            ->find();
        if($item['timeslot']){
            $check_timeslot=json_decode($item['timeslot'],true);
            $this->assign('check_timeslot',$check_timeslot);
            $this->assign('k',0);
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                $data2 = array();
                foreach ($data['timeslot'] as $k => $v) {
                    array_push($data2, $v);
                }
                $data['timeslot'] = json_encode($data2);
                if (!empty($item)) {
                    $res = Db::name('set_seckill')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_seckill')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        $timeslot=array();
        for($i=0;$i<24;$i++){
            if($i<10){
                $a='0'.$i.':00';
            }else{
                $a=$i.':00';
            }
            array_push($timeslot,$a);
        }
        $this->assign('timeslot',$timeslot);
        return $this->fetch();
    }
    public function indexad(){
        $item=Db::name('set')
            ->where('acid',1)
            ->find();
        $item['qrcode']=to_media_url($item['qrcode']);
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if(!isset($data['is_gz'])){
                    $data['is_gz']=0;
                }
                unset($data['file']);
                if (!empty($item)) {
                    $res = Db::name('set')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function kefu(){
        $item=Db::name('set')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if(isset($data['file'])){
                    unset($data['file']);
                }
                if (!empty($item)) {
                    $res = Db::name('set')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function message(){
        $item=Db::name('set_sms')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_sms')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_sms')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function smsSet(){
        $item=Db::name('set_sms')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            $data = input('post.');
            if(!empty($item)){
                $res=Db::name('set_sms')->where('acid',1)->update($data);
                if($res){
                    if($res==0){
                        $this->result('0','无更新');
                    }else{
                        $this->result('0','修改成功');
                    }
                }else{
                    $this->result('1','修改失败');
                }
            }else{
                $data['acid']=1;
                $res=Db::name('set_sms')->insert($data);
                if($res){
                    $this->result('0','添加成功');
                }else{
                    $this->result('1','添加失败');
                }
            }
        }
        return $this->fetch('sms');
    }
    public function thinkSms(){
        $item=Db::name('set_sms')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_sms')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_sms')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }

        return $this->fetch();
    }
    public function tplmsg(){
        $item=Db::name('set')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function fenxiao(){
        $item=Db::name('set')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                $data['ztyj'] = $data['ztyj'] / 100;
                $data['jtyj'] = $data['jtyj'] / 100;
                $data['jsyj'] = $data['jsyj'] / 100;
                unset($data['file']);
                if (!empty($item)) {
                    $res = Db::name('set')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function jigou(){
        $item=Db::name('set_jigou')
            ->where('acid',1)
            ->find();
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if($data['loadmorenum']<=0){
                    return $this->result('1','加载更多数量须大于0');
                }
                if(isset($data['file'])){
                    unset($data['file']);
                }
                if (!empty($item)) {
                    $res = Db::name('set_jigou')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_jigou')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function alipay(){
        $item=Db::name('set_alipay')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['privatekey']){
                $item['privatekey']=substr_replace($item['privatekey'],'*********************************************',0);
            }
            if($item['publickey']){
                $item['publickey']=substr_replace($item['publickey'],'************************************',0);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if(isset($data['file'])){
                    unset($data['file']);
                }
                if (!empty($item)) {
                    $res = Db::name('set_alipay')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_alipay')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function h5(){
        $item=Db::name('set_h5')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['appsecret']){
                $item['appsecret']=substr_replace($item['appsecret'],'***************',10,17);
            }
            if($item['mchid']){
                $item['mchid']=substr_replace($item['mchid'],'******',2,6);
            }
            if($item['paysecret']){
                $item['paysecret']=substr_replace($item['paysecret'],'***************',10,17);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if(isset($data['file'])){
                    unset($data['file']);
                }
                if (!empty($item)) {
                    $res = Db::name('set_h5')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_h5')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function kuaishouapp(){
        $item=Db::name('set_mpkuaishou')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['appsecret']){
                $item['appsecret']=substr_replace($item['appsecret'],'***************',10,17);
            }
            if($item['mchid']){
                $item['mchid']=substr_replace($item['mchid'],'******',2,6);
            }
            if($item['paysecret']){
                $item['paysecret']=substr_replace($item['paysecret'],'***************',10,17);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_mpkuaishou')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_mpkuaishou')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function baiduapp(){
        $item=Db::name('set_mpbaidu')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['appsecret']){
                $item['appsecret']=substr_replace($item['appsecret'],'***************',10,17);
            }
            if($item['mchid']){
                $item['mchid']=substr_replace($item['mchid'],'******',2,6);
            }
            if($item['paysecret']){
                $item['paysecret']=substr_replace($item['paysecret'],'***************',10,17);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_mpbaidu')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_mpbaidu')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function alipayapp(){
        $item=Db::name('set_mpalipay')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['appsecret']){
                $item['appsecret']=substr_replace($item['appsecret'],'***************',10,17);
            }
            if($item['mchid']){
                $item['mchid']=substr_replace($item['mchid'],'******',2,6);
            }
            if($item['paysecret']){
                $item['paysecret']=substr_replace($item['paysecret'],'***************',10,17);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_mpalipay')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_mpalipay')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function toutiaoapp(){
        $item=Db::name('set_mptoutiao')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['appsecret']){
                $item['appsecret']=substr_replace($item['appsecret'],'***************',10,17);
            }
            if($item['mchid']){
                $item['mchid']=substr_replace($item['mchid'],'******',2,6);
            }
            if($item['paysecret']){
                $item['paysecret']=substr_replace($item['paysecret'],'***************',10,17);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_mptoutiao')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_mptoutiao')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function smallapp(){
        $item=Db::name('set_smallapp')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['appsecret']){
                $item['appsecret']=substr_replace($item['appsecret'],'***************',10,17);
            }
            if($item['mchid']){
                $item['mchid']=substr_replace($item['mchid'],'******',2,6);
            }
            if($item['paysecret']){
                $item['paysecret']=substr_replace($item['paysecret'],'***************',10,17);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_smallapp')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_smallapp')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function apps(){
        $item=Db::name('set_app')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['appsecret']){
                $item['appsecret']=substr_replace($item['appsecret'],'***************',10,17);
            }
            if($item['mchid']){
                $item['mchid']=substr_replace($item['mchid'],'******',2,6);
            }
            if($item['paysecret']){
                $item['paysecret']=substr_replace($item['paysecret'],'***************',10,17);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_app')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_app')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function pc(){
        $item=Db::name('set_pc')
            ->where('acid',1)
            ->find();
        if(session('agid')!='1' && session('username')!='admin'){
            if($item['appsecret']){
                $item['appsecret']=substr_replace($item['appsecret'],'***************',10,17);
            }
            if($item['mchid']){
                $item['mchid']=substr_replace($item['mchid'],'******',2,6);
            }
            if($item['paysecret']){
                $item['paysecret']=substr_replace($item['paysecret'],'***************',10,17);
            }
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                if (!empty($item)) {
                    $res = Db::name('set_pc')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set_pc')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
    public function basic(){
        $item=Db::name('set')
            ->where('acid',1)
            ->find();
        if(!empty($item)){
            $item['share_icon'] = to_media_url($item['share_icon']);
        }
        $this->assign('item',$item);
        if(request()->isPost()){
            if(session('agid')=='2'){
                $this->result('1','暂无权限');
            }else {
                $data = input('post.');
                unset($data['file']);
                if (!empty($item)) {
                    $res = Db::name('set')->where('acid', 1)->update($data);
                    if ($res) {
                        if ($res == 0) {
                            $this->result('0', '无更新');
                        } else {
                            $this->result('0', '修改成功');
                        }
                    } else {
                        $this->result('1', '修改失败');
                    }
                } else {
                    $data['acid'] = 1;
                    $res = Db::name('set')->insert($data);
                    if ($res) {
                        $this->result('0', '添加成功');
                    } else {
                        $this->result('1', '添加失败');
                    }
                }
            }
        }
        return $this->fetch();
    }
}
